package com.wrial.offer;
/*
 * @Author  Wrial
 * @Date Created in 10:50 2020/4/2
 * @Description 调整数组顺序使奇数位于偶数前面
 */

public class FaceTest_21 {

    // 使用两个数组完成
    public int[] exchange(int[] nums) {

        int[] ans1 = new int[nums.length];
        int[] ans2 = new int[nums.length];
        int j1 = 0;
        int j2 = 0;
        for (int num : nums) {
            if (num % 2 == 0) {
                ans1[j1++] = num;
            } else {
                ans2[j2++] = num;
            }
        }
        if (ans1 == null) return ans2;
        if (ans2 == null) return ans1;
        for (int i : ans1) {
            // 防止越界
            if(j2>ans2.length-1) continue;
            ans2[j2] = i;

            j2++;
        }
        return ans2;

    }
}
